/**
 * All rights Reserved, Designed By Android_Robot
 *
 * @Title: HuoDongFaBuActivity.java
 * @Package com.jiyi.activity.zone
 * @Description: TODO(用一句话描述该文件做什么)
 * @author: HYM
 * @date: 2017-6-8 下午5:02:21
 * @version V1.0
 */
package com.jiyi.activity.zone;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.Target;
import com.google.gson.Gson;
import com.hyphenate.easeui.EaseConstant;
import com.jiyi.activity.LActivity;
import com.jiyi.activity.Map_MyLocationActivity;
import com.jiyi.adapter.CommonAdapter;
import com.jiyi.adapter.ViewHolder;
import com.jiyi.bean.zone.ZoneHuoDongBean;
import com.jiyi.bean.zone.ZoneHuoDongCoverBean;
import com.jiyi.bean.zone.ZoneHuoDongCoverJson;
import com.jiyi.bean.zone.ZoneQunZuBean;
import com.jiyi.common.StringInterface;
import com.jiyi.common.VolleyRequest;
import com.jiyi.easemob.util.ClouldChatType;
import com.jiyi.easemob.util.UserHelp;
import com.jiyi.easemob.view.EasemobChatActivity;
import com.jiyi.event.HuoDongListEvent;
import com.jiyi.inteface.PickPopInterface;
import com.jiyi.inteface.WebApi;
import com.jiyi.view.PickPopView;
import com.jiyi.widget.PopTextView;
import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.data.Type;
import com.jzxiang.pickerview.listener.OnDateSetListener;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppBase;
import com.swift.maintenance.base.AppConfig;
import com.swift.maintenance.utils.CheckUtil;
import com.swift.maintenance.utils.PermissionUtil;
import com.swift.maintenance.utils.ToastUtil;
import com.swift.maintenance.utils.UserInfoUtil;
import com.swift.utils.CameraUtils;
import com.swift.utils.DateUtils;
import com.swift.utils.DeviceUtil;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.PostFormBuilder;
import com.zhy.http.okhttp.callback.StringCallback;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

/**
 * @ClassName: HuoDongFaBuActivity
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: HYM
 * @date: 2017-6-8 下午5:02:21
 *
 */
public class HuoDongFaBuActivity extends LActivity implements
        PickPopInterface, OnDateSetListener {

    @BindView(R.id.tvBack)
    TextView tvBack;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvSearch)
    TextView tvSearch;

    @BindView(R.id.gvDefaultCover)
    GridView gvDefaultCover;
    @BindView(R.id.ivLogo)
    ImageView ivLogo;
    @BindView(R.id.ptvState)
    PopTextView ptvState;
    @BindView(R.id.root)
    RelativeLayout root;
    @BindView(R.id.etTheme)
    TextView etTheme;
    @BindView(R.id.etIntroduction)
    TextView etIntroduction;
    @BindView(R.id.tvStartDate)
    TextView tvStartDate;
    @BindView(R.id.tvEndDate)
    TextView tvEndDate;
    @BindView(R.id.etMaxNum)
    TextView etMaxNum;
    @BindView(R.id.llPick)
    LinearLayout llPick;
    @BindView(R.id.etAddress)
    EditText etAddress;

    List<ZoneHuoDongCoverBean> coverList = new ArrayList<ZoneHuoDongCoverBean>();
    private CommonAdapter mAdapter;

    ArrayAdapter<String> stateAdapter;

    PickPopView mPickPopView;

    // 图片路径
    private Uri CameraUri;
    // 拍摄事件
    public final int CAMARE_CODE = 1;
    // 从相册选择事件
    public final int CHOOSE_PICTURE = 2;
    // 指定群组
    public final int ZHIDING_QUNZU = 3;
    // 定位事件
    final int LOCATION = 4;
    // 图片路径
    private String filePath;
    // 经纬度
    String latitude, longitude;

    // 进度条
    Dialog dialog;
    private View datexmlView;
    // 指定的群组对象
    ZoneQunZuBean zhiDingQunZu;

    TimePickerDialog mDialogYearMonth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_huodong_fabu);
        ButterKnife.bind(this);
        init();

    }



    @Override
    public void onBackPressed() {
        onBackActivity(root);
    }

    @Override
    protected void onDestroy() {
        hideDialog(dialog);
        super.onDestroy();

    }


    /**
     * @author: HYM
     * @Title: init
     * @Description: TODO(这里用一句话描述这个方法的作用) void
     * @date: 2017-6-8
     */
    private void init() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            //获取前面点击的对象
            x = getIntent().getIntExtra("x", 0);
            y = getIntent().getIntExtra("y", 0);
            //初始化开场动画和退场动画
            setupAnimator(root,x,y);
        }


        setTop();

        setViewStatus();
        getCoverData();
        setCoverAdapter();
        setStateAdapter();
        mPickPopView = new PickPopView(this, this);
    }

    /**
     * @author: HYM
     * @Title: setViewStatus
     * @Description: TODO(这里用一句话描述这个方法的作用) void
     * @date: 2017-6-30
     */
    private void setViewStatus() {
        // 设置必填项检测提示
        etTheme.setTag(R.id.tag_view_empty, "活动主题不能为空");
        etMaxNum.setTag(R.id.tag_view_empty, "活动最大人数不能为空");
        tvStartDate.setTag(R.id.tag_view_empty, "开始时间不能为空");
        tvEndDate.setTag(R.id.tag_view_empty, "结束时间不能为空");
        etAddress.setTag(R.id.tag_view_empty, "活动地址不能为空");


        //初始化日期控件
        mDialogYearMonth = new TimePickerDialog.Builder()
                .setTitleStringId("日期选择")
                .setType(Type.ALL)
                .setThemeColor(getResources().getColor(R.color.colorPrimary))
                .setCallBack(this)
                .build();
    }

    /**
     * @author: HYM
     * @Title: getCoverData
     * @Description: TODO(这里用一句话描述这个方法的作用) void
     * @date: 2017-6-30
     */
    private void getCoverData() {

        Map<String, String> params = new HashMap<String, String>();
        params.put(AppConfig.ACCESS_TOKEN, UserInfoUtil.getCurrentUserAccessToken());

        VolleyRequest.StringRequestPost(this,
                WebApi.ZONE_ALL_HUODONG_COVER_LIST, "", params,
                new StringInterface(this) {

                    @Override
                    public void stringSuccess(String result) {
                        try {
                            JSONObject obj = new JSONObject(result);
                            String status = obj.getString("status");
                            String info = obj.getString("info");
                            if (status.equals("200")) {
                                ZoneHuoDongCoverJson temp = new Gson()
                                        .fromJson(result,
                                                ZoneHuoDongCoverJson.class);
                                if (temp == null || temp.getData() == null) {
                                    if (temp.getData().size() <= 0) {
                                        // 没有系统封面
                                    }
                                } else {
                                    coverList.clear();
                                    coverList.addAll(temp.getData());
                                    mAdapter.notifyDataSetChanged();
                                    int size = coverList.size();
                                    // 得到像素密度
                                    float density = DeviceUtil.getInstance()
                                            .getBiLi(); // 像素密度

                                    // 根据item的数目，动态设定gridview的宽度,现假定每个item的宽度和高度均为100dp，列间距为5dp
                                    ViewGroup.LayoutParams params = gvDefaultCover
                                            .getLayoutParams();
                                    int itemWidth = (int) (90 * density);
                                    int spacingWidth = (int) (10 * density);

                                    params.width = itemWidth * size
                                            + (size - 1) * spacingWidth;
                                    gvDefaultCover
                                            .setStretchMode(GridView.NO_STRETCH); // 设置为禁止拉伸模式
                                    gvDefaultCover.setNumColumns(size);
                                    gvDefaultCover
                                            .setHorizontalSpacing(spacingWidth);
                                    gvDefaultCover.setColumnWidth(itemWidth);
                                    gvDefaultCover.setLayoutParams(params);

                                    // initCoverData();
                                    // mAdapter.notifyDataSetChanged();
                                }

                            } else {
                                ToastUtil.getInstances().showMsg(info);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        } finally {

                        }
                    }

                    @Override
                    public void stringError(VolleyError error) {
                        ToastUtil.getInstances().showMsg(
                                R.string.err_http_response);
                    }
                });
    }

    /**
     * @author: HYM
     * @Title: setStateAdapter
     * @Description: TODO(这里用一句话描述这个方法的作用) void
     * @date: 2017-6-9
     */
    private void setStateAdapter() {
        // 设置参加设置状态的适配器
        stateAdapter = new ArrayAdapter<String>(this,
                R.layout.item_huodong_join_state, getResources()
                .getStringArray(R.array.huodong_join_state));
        ptvState.setListAdapter(stateAdapter);
        ptvState.setOnItemClick(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                if (position == 0) {
                    ptvState.doListItemClick(((TextView) view).getText()
                            .toString(), position + "");
                    zhiDingQunZu = null;
                } else if (position == 1) {
                    ptvState.doListItemClick(ptvState.getText().toString(),
                            position + "");
                    // 指定群组
                    Intent zhidingIntent = new Intent(HuoDongFaBuActivity.this,
                            ZoneZhiDingQunZuActivity.class);
                    startActivityForResult(zhidingIntent, ZHIDING_QUNZU);
                }
            }
        });
    }

    /**
     * @author: HYM
     * @Title: setCoverAdapter
     * @Description: TODO(这里用一句话描述这个方法的作用) void
     * @date: 2017-6-9
     */
    private void setCoverAdapter() {
        mAdapter = new CommonAdapter<ZoneHuoDongCoverBean>(this, coverList,
                R.layout.item_huodong_default_cover) {

            @Override
            public void convert(final ViewHolder holder,
                                final ZoneHuoDongCoverBean t) {
                holder.setImage(R.id.ivCover, t.getCover_path());
                holder.setOnClickListener(R.id.rbCheck, new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // 重置全部的封面为未选中
                        for (int i = 0; i < coverList.size(); i++) {
                            coverList.get(i).setIsCheck(false);
                        }
                        // 然后设置选中
                        coverList.get(holder.getPosition()).setIsCheck(true);
                        mAdapter.notifyDataSetChanged();
                        new getImageCacheAsyncTask(HuoDongFaBuActivity.this,
                                ivLogo).execute(t.getCover_path());
                        hideChoose();
                    }
                });
                holder.setChecked(R.id.rbCheck, t.getIsCheck());
            }
        };
        gvDefaultCover.setAdapter(mAdapter);
    }

    /**
     * @author: HYM
     * @Title: setTop
     * @Description: TODO(这里用一句话描述这个方法的作用) void
     * @date: 2017-6-9
     */
    private void setTop() {
        tvBack.setText("");
        tvTitle.setText("发布活动");
        tvSearch.setVisibility(View.GONE);
    }

    @OnClick({R.id.tvBack, R.id.llPick, R.id.ivLocation, R.id.bottom,
            R.id.tvStartDate, R.id.tvEndDate})
    public void onClick(View view) {
        Intent intent = null;
        switch (view.getId()) {
            case R.id.tvBack:
                onBackActivity(root);
                break;
            case R.id.llPick:
                mPickPopView.showPopWindow();
                break;
            case R.id.tvStartDate:
                mDialogYearMonth.show(getSupportFragmentManager(), "tvStartDate");
                break;
            case R.id.tvEndDate:
                mDialogYearMonth.show(getSupportFragmentManager(), "tvEndDate");
                break;
            case R.id.ivLocation:
                // 定位
                if (!DeviceUtil.getInstance().isGpsEnable()) {
                    ToastUtil.getInstances().showMsg("请打开GPS定位");
                    return;
                }

                if (PermissionUtil.checkPermission(this,PermissionUtil.LOCATION))
                {
                    gotoMap();
                }


                break;
            case R.id.bottom:
                if (TextUtils.isEmpty(filePath)) {
                    ToastUtil.getInstances().showMsg("请先选择封面");
                    return;
                }

                if (CheckUtil.checkView(etTheme, etMaxNum, tvStartDate, tvEndDate,
                        etAddress)) {
                    if (!TextUtils.isEmpty(etMaxNum.getText().toString())) {
                        if (Integer.parseInt(etMaxNum.getText().toString()) > AppConfig.max_huodong) {
                            ToastUtil.getInstances().showMsg(
                                    "最大人数不能大于" + AppConfig.max_huodong);
                            return;
                        }
                    }

                    if (DateUtils.compare(tvStartDate.getText().toString(),
                            tvEndDate.getText().toString(), DateUtils.DATEFORMAT)) {
                        ToastUtil.getInstances().showMsg("开始时间不能大于结束时间");
                        return;
                    }

                    // 执行发布
                    doPost();
                }

                break;
            default:
                break;
        }
    }

    /**
     * @author: HYM
     * @Title: doPost
     * @Description: TODO(这里用一句话描述这个方法的作用) void
     * @date: 2017-6-30
     */
    private void doPost() {
        String webApi = WebApi.ZONE_HUODONG_FABU;
        Map<String, String> params = new HashMap<String, String>();
        params.put(AppConfig.ACCESS_TOKEN, UserInfoUtil.getCurrentUserAccessToken());
        params.put("theme", etTheme.getText().toString());
        params.put("introduction", etIntroduction.getText().toString());
        params.put("address", etAddress.getText().toString());
        params.put("start_time", tvStartDate.getText().toString());
        params.put("end_time", tvEndDate.getText().toString());
        params.put("max_user_num", etMaxNum.getText().toString());
        params.put("join_type", ptvState.getSelectedId());
        if (zhiDingQunZu != null) {
            params.put("group_id", zhiDingQunZu.getId());
        }

        PostFormBuilder postForm = OkHttpUtils.post().url(webApi);
        postForm.params(params);
        if (!TextUtils.isEmpty(filePath)) {
            File file = new File(filePath);
            postForm.addFile("cover", "huodong_logo.jpg", file);
        }

        dialog = showDialog(dialog);
        postForm.build().execute(new StringCallback() {

            @Override
            public void onError(Call arg0, Exception exception, int arg2) {
                hideDialog(dialog);
                ToastUtil.getInstances().showMsg(exception.getMessage());
            }

            @Override
            public void onResponse(String result, int arg1) {
                try {
                    JSONObject obj = new JSONObject(result);
                    String status = obj.getString("status");
                    String info = obj.getString("info");
                    if (status.equals("200")) {
                        ToastUtil.getInstances().showMsg(info);
                        String data = obj.getString("data");
                        JSONObject dataJson = new JSONObject(data);
                        // 得到刚刚创建的活动ID
                        String id = dataJson.getString("id");
                        // 得到刚刚创建的活动封面
                        String cover = dataJson.getString("cover");
                        // String cover =
                        // "http://test.jyfire.cn/Upload/20170711/596473fd1b898.jpg";

                        setResult(RESULT_OK);
                        EventBus.getDefault().post(
                                new HuoDongListEvent(
                                        HuoDongListEvent.MY_HUODONG_FRAGMENT));
                        Log.d("post huodong event ", " MY_HUODONG_FRAGMENT");
                        onBackActivity(root);
                        // 判断如果有指定群组 则跳转到群组
                        if (zhiDingQunZu != null) {
                            Intent intent2 = new Intent(
                                    HuoDongFaBuActivity.this,
                                    EasemobChatActivity.class);
                            intent2.putExtra(ClouldChatType.INTENT_USER_PIC,
                                    zhiDingQunZu.getGroup_head());
                            intent2.putExtra("id", zhiDingQunZu.getId());
                            intent2.putExtra("name", zhiDingQunZu.getName());
                            intent2.putExtra("easemobgid",
                                    zhiDingQunZu.getHx_group_id());
                            intent2.putExtra(ClouldChatType.INTENT_Group_Id,
                                    zhiDingQunZu.getId());
                            intent2.putExtra("easeMobChatType",
                                    EaseConstant.CHATTYPE_GROUP);
                            intent2.putExtra("isShareHuoDong", true);
                            intent2.putExtra("zhiDingQunZu",
                                    new Gson().toJson(zhiDingQunZu));

                            ZoneHuoDongBean zhiDingHuoDong = new ZoneHuoDongBean();
                            zhiDingHuoDong.setAddress(etAddress.getText()
                                    .toString());
                            zhiDingHuoDong.setStart_time(tvStartDate.getText()
                                    .toString());
                            zhiDingHuoDong.setAttendPer(etMaxNum.getText()
                                    .toString());
                            zhiDingHuoDong.setCheck_type(ptvState
                                    .getSelectedId());
                            zhiDingHuoDong.setId(id);
                            zhiDingHuoDong.setIntroduction(etIntroduction
                                    .getText().toString());
                            zhiDingHuoDong.setTheme(etTheme.getText()
                                    .toString());
                            zhiDingHuoDong.setCover(cover);
                            zhiDingHuoDong.setFlag(1);
                            intent2.putExtra("zhiDingHuoDong",
                                    new Gson().toJson(zhiDingHuoDong));
                            intent2.putExtra(ClouldChatType.INTENT_MSG_TP,
                                    ClouldChatType.TYPE_NEIGHBOUR);
                            startActivity(intent2);
                        }
                    } else if (status.equals("404") && info.contains("尚未登录")) {
                        ToastUtil.getInstances().showMsg("尚未登录或该用户在其他地方登录，请重新登录！");
                        //清除环信登录
                        UserHelp.getInstance().clearUser(AppBase.Context, true);
                        return;
                    } else {
                        ToastUtil.getInstances().showMsg(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                } finally {
                    hideDialog(dialog);
                }
            }
        });
    }

    @Override
    public void OnShootListener() {

        if(PermissionUtil.checkPermission(this,PermissionUtil.CARAME))
        {
            useCamere();
        }
    }

    @Override
    public void OnAlbumListener() {
        Intent openAlbumIntent = new Intent(Intent.ACTION_GET_CONTENT);
        openAlbumIntent.setType("image/*");
        startActivityForResult(openAlbumIntent, CHOOSE_PICTURE);
        mPickPopView.hidePopWindow();
    }

    @Override
    public void OnCancleListener() {
        // TODO Auto-generated method stub

    }

    @Override
    public void OnShowListener() {
        // TODO Auto-generated method stub

    }

    @Override
    public void OnHideListener() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == CAMARE_CODE && resultCode == RESULT_OK) {
            try {
                Glide.with(this).load(new File(filePath)).into(ivLogo);
                hideChoose();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (requestCode == CHOOSE_PICTURE) {
            if (resultCode == RESULT_OK) {
                if (data != null) {
                    Uri temp = data.getData();
                    filePath = CameraUtils.getImageAbsolutePath(this, temp);
                    Glide.with(this).load(new File(filePath)).into(ivLogo);
                    hideChoose();
                }

            }
        } else if (requestCode == ZHIDING_QUNZU) {
            if (resultCode == RESULT_OK) {
                if (data != null) {
                    String qunzu_obj = data.getStringExtra("qunzu_obj");
                    zhiDingQunZu = new Gson().fromJson(qunzu_obj,
                            ZoneQunZuBean.class);
                    ptvState.setText(zhiDingQunZu.getName());

                }
            }
        }
        if (requestCode == LOCATION) {
            if (resultCode == RESULT_OK) {
                etAddress.setText(data.getStringExtra("address"));
                latitude = data.getStringExtra("latitude");
                longitude = data.getStringExtra("longitude");
                Log.e("latitude    ", latitude);
                Log.e("longitude    ", longitude);
            }
        }
    }

    /**
     * @author: HYM
     * @Title: hideChoose
     * @Description: TODO(logo在选择完成后，隐藏之前的选择提示，并设置当前Logo可以点击重新选择) void
     * @date: 2017-6-13
     */
    void hideChoose() {
        llPick.setVisibility(View.GONE);
        ivLogo.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mPickPopView.showPopWindow();
            }
        });
    }

    @Override
    public void onAnimatStart() {

    }

    @Override
    public void onAnimatStop() {
        finish();
    }

    @Override
    public void onDateSet(TimePickerDialog timePickerView, long millseconds) {
        String type = timePickerView.getTag();
        if (type.equals("tvStartDate"))
        {
            tvStartDate.setText(DateUtils.timeStampToStr(millseconds/1000,DateUtils.YMDHMS_FORMAT));
        }
        else if (type.equals("tvEndDate"))
        {
            tvEndDate.setText(DateUtils.timeStampToStr(millseconds/1000,DateUtils.YMDHMS_FORMAT));
        }

    }


    private class getImageCacheAsyncTask extends AsyncTask<String, Void, File> {
        private final Context context;
        private ImageView ivLogo;

        public getImageCacheAsyncTask(Context context, ImageView ivLogo) {
            this.context = context;
            this.ivLogo = ivLogo;
        }

        @Override
        protected File doInBackground(String... params) {
            String imgUrl = params[0];
            try {
                return Glide
                        .with(context)
                        .load(imgUrl)
                        .downloadOnly(Target.SIZE_ORIGINAL,
                                Target.SIZE_ORIGINAL).get();
            } catch (Exception ex) {
                return null;
            }
        }

        @Override
        protected void onPostExecute(File result) {
            if (result == null) {
                return;
            }
            // 此path就是对应文件的缓存路径
            filePath = result.getPath();
            Log.e("filePath  ", filePath);
            Bitmap bmp = BitmapFactory.decodeFile(filePath);
            ivLogo.setImageBitmap(bmp);

        }
    }

    private void useCamere() {
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

        File fileDir = new File(AppConfig.DIR_IMAGE);
        // 判断文件目录是否存在
        if (!fileDir.exists()) {
            fileDir.mkdirs();
        }

        filePath = AppConfig.DIR_IMAGE + "temp" + new Date().getTime() + ".jpg";
        File file = new File(filePath);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            //如果是7.0或以上，使用getUriForFile()获取文件的Uri
            CameraUri = FileProvider.getUriForFile(this, "com.swift.maintenance.updateprovider", file);
        } else {
            CameraUri = CameraUtils
                    .getOutputMediaFileUri(CameraUtils.MEDIA_TYPE_IMAGE);
            filePath=CameraUri.getPath();
        }


        intent.putExtra(MediaStore.EXTRA_OUTPUT, CameraUri);
        startActivityForResult(intent, CAMARE_CODE);
        mPickPopView.hidePopWindow();
    }

    private void gotoMap()
    {
        Intent intent = new Intent(this, Map_MyLocationActivity.class);
        intent.putExtra("mapType", 1);
        startActivityForResult(intent, LOCATION);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == PermissionUtil.CARAME)
        {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED)
            {
                useCamere();
            }
            else {
                ToastUtil.getInstances().showMsg("没有访问摄像机的权限");
            }
        }
        else if (requestCode == PermissionUtil.LOCATION)
        {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
            {
                gotoMap();
            }
        }
    }
}
